package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.JkBanner;
import com.ruoyi.service.IJkBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * banner管理Controller
 *
 * @author ruoyi
 * @date 2023-09-05
 */
@RestController
@RequestMapping("/operate/banner")
public class JkBannerController extends BaseController
{
    @Autowired
    private IJkBannerService jkBannerService;

    /**
     * 查询banner管理列表
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(JkBanner jkBanner)
    {
        startPage();
        List<JkBanner> list = jkBannerService.selectJkBannerList(jkBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner管理列表
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:export')")
    @Log(title = "banner管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkBanner jkBanner)
    {
        List<JkBanner> list = jkBannerService.selectJkBannerList(jkBanner);
        ExcelUtil<JkBanner> util = new ExcelUtil<JkBanner>(JkBanner.class);
        util.exportExcel(response, list, "banner管理数据");
    }

    /**
     * 获取banner管理详细信息
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jkBannerService.selectJkBannerById(id));
    }

    /**
     * 新增banner管理
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:add')")
    @Log(title = "banner管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JkBanner jkBanner)
    {
        return toAjax(jkBannerService.insertJkBanner(jkBanner));
    }

    /**
     * 修改banner管理
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:edit')")
    @Log(title = "banner管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkBanner jkBanner)
    {
        return toAjax(jkBannerService.updateJkBanner(jkBanner));
    }

    /**
     * 删除banner管理
     */
    @PreAuthorize("@ss.hasPermi(' operate:banner:remove')")
    @Log(title = "banner管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jkBannerService.deleteJkBannerByIds(ids));
    }
}
